package com.sixth.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixth.dao.HeadDao;
import com.sixth.entity.Head;
import com.sixth.entity.TableResult;
import com.sixth.service.HeadNavigationService;
import com.sixth.until.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: self-tui-education
 * @description:
 * @author: C
 * @create: 2022-04-16 00:20
 **/
@Service
public class HeadNavigationServiceimpl implements HeadNavigationService {
@Autowired
  private HeadDao headDao;
    @Override
    public CommonResult deleteFindById(Head head) {
        Integer headId=head.getHeadId();
        System.out.println("headId++++++++++++++"+headId);
        int row =headDao.deleteByPrimaryKey(headId);
        if (row>0){
            return new CommonResult(2000,"删除成功","null");
        }else {
            return new CommonResult(5000,"删除失败","null");
        }
    }



    @Override
    public TableResult selectAllHead(Integer currentPage, Integer pageSize, Head head) {
         PageHelper.startPage(currentPage,pageSize);
         String headName = head.getHeadName();
         String isDiable = head.getIsDiable();
         System.out.println(headName+isDiable);
         List<Head> eduTeachers = headDao.selectHeadByCondition(headName,isDiable);
        PageInfo<Head> pageInfo = new PageInfo<>(eduTeachers);

         return new TableResult(2000,"查询成功",pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public CommonResult addHead(Head head) {
        head.setIsDelete("0");
        int i = headDao.insertSelective(head);
        return new CommonResult(2000,"添加成功",null);

    }

    @Override
    public CommonResult UpdateHead(Head head) {
        int i = headDao.updateByPrimaryKeySelective(head);
        if (i != 0) {
            return new CommonResult(2000,"修改成功",null);
        }
        return new CommonResult(5000,"修改失败",null);
    }

    @Override
    public CommonResult changeStatus(Integer headId, String isDiable) {
        int i = headDao.changeStatusByid(headId, isDiable);
        if (i != 0) {
            return new CommonResult(2000,"修改状态成功",null);
        }
        return new CommonResult(2000,"修改失败",null);
    }

}
